﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using tintuc.Entities;

namespace tintuc.COMM
{
    public class Admins
    {
        #region bảng users và bảng độc giả
        public docgia getby_tk_docgia(string _tentaikhoan, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from docgia where  tendangnhap like  N'" + _tentaikhoan + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                docgia obj = new docgia();
                obj = (docgia)CBO.FillObject(dr, typeof(docgia));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public users getby_tk_users_ten(string _tentaikhoan, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from users where  username like  N'" + _tentaikhoan + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                users obj = new users();
                obj = (users)CBO.FillObject(dr, typeof(users));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public users getby_tk_users_id(string _userid, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from users where  userid like  N'" + _userid + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                users obj = new users();
                obj = (users)CBO.FillObject(dr, typeof(users));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public int capnhap_tt_docgia(string _tendangnhap, bool _trangthai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@tendangnhap", _tendangnhap);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", _trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_trangthai_khachhang", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int capnhap_tt_Users(string _tendangnhap, bool _trangthai, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@username", _tendangnhap);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", _trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_trangthai_users", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int Login_users(string _username, string _password, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@username", _username);
                i = i + 1;
                prms[i] = new SqlParameter("@password", _password);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_login", ref prms, 3, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public int save_users(users vusers, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[10];
                prms[i] = new SqlParameter("@userid", vusers.Userid);
                i = i + 1;
                prms[i] = new SqlParameter("@username", vusers.Username);
                i = i + 1;
                prms[i] = new SqlParameter("@password", vusers.Password);
                i = i + 1;
                prms[i] = new SqlParameter("@usertype", vusers.Usertype);
                i = i + 1;
                prms[i] = new SqlParameter("@hoten", vusers.Hoten);
                i = i + 1;
                prms[i] = new SqlParameter("@diachi", vusers.Diachi);
                i = i + 1;
                prms[i] = new SqlParameter("@sodienthoai", vusers.Sodienthoai);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vusers.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("dbo.sp_save_users", ref prms, 9, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public DataTable getall_khachhang_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_khachhang_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_users_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_users_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }
        #endregion

        #region bang chuyen muc
        public DataTable getall_chuyenmuc_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_chuyenmuc_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_chuyenmuc(chuyenmuc vchuyenmuc, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@machuyenmuc", vchuyenmuc.Machuyenmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@tenchuyenmuc", vchuyenmuc.Tenchuyenmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vchuyenmuc.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_chuyenmuc]", ref prms, 4, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public chuyenmuc getby_chuyenmuc(string _machuyenmuc, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from chuyenmuc where machuyenmuc like  N'" + _machuyenmuc + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                chuyenmuc obj = new chuyenmuc();
                obj = (chuyenmuc)CBO.FillObject(dr, typeof(chuyenmuc));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region bang giai dau
        public DataTable getall_giaidau_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_giaidau_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_giaidau_para_page(int _magiaidau, int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@machuyenmuc", _magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_giaidau_para_page]", ref prms, 4, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_giaidau(giaidau vgiaidau, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[6];
                prms[i] = new SqlParameter("@magiaidau", vgiaidau.Magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@machuyenmuc", vgiaidau.Machuyenmuc);
                i = i + 1;
                prms[i] = new SqlParameter("@tengiaidau", vgiaidau.Tengiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vgiaidau.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_chuyenmuc]", ref prms, 5, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public giaidau getby_giaidau(string _magiaidau, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from giaidau where magiaidau like  N'" + _magiaidau + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                giaidau obj = new giaidau();
                obj = (giaidau)CBO.FillObject(dr, typeof(giaidau));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region bang xep hang
        public DataTable getall_bangxephang_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_bangxephang_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_bangxephang_para_page(int _magiaidau, int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@magiaidau", _magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_bangxephang_para_page]", ref prms, 4, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_bangxephang(bangxephang vbangxephang, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[8];
                prms[i] = new SqlParameter("@mabangxephang", vbangxephang.Mabangxephang);
                i = i + 1;
                prms[i] = new SqlParameter("@magiaidau", vbangxephang.Magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@bangxephang", vbangxephang.Bangxephang);
                i = i + 1;
                prms[i] = new SqlParameter("@thoigian", vbangxephang.Thoigian);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vbangxephang.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngay", vbangxephang.Ngay);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_bangxephang]", ref prms, 7, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public bangxephang getby_bangxephang(string _mabangxephang, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from bangxephang where mabangxephang like  N'" + _mabangxephang + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                bangxephang obj = new bangxephang();
                obj = (bangxephang)CBO.FillObject(dr, typeof(bangxephang));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region lich thi dau
        public DataTable getall_licthidau_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_licthidau_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public DataTable getall_licthidau_para_page(int _magiaidau, int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@magiaidau", _magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_licthidau_para_page]", ref prms, 4, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_licthidau(licthidau vlichthidau, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[8];
                prms[i] = new SqlParameter("@malichthidau", vlichthidau.Malichthidau);
                i = i + 1;
                prms[i] = new SqlParameter("@magiaidau", vlichthidau.Magiaidau);
                i = i + 1;
                prms[i] = new SqlParameter("@lichthidau", vlichthidau.Lichthidau);
                i = i + 1;
                prms[i] = new SqlParameter("@thoigian", vlichthidau.Thoigian);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vlichthidau.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@ngay", vlichthidau.Ngay);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_licthidau]", ref prms, 7, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public licthidau getby_licthidau(string _mabangxephang, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from licthidau where malichthidau like  N'" + _mabangxephang + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                licthidau obj = new licthidau();
                obj = (licthidau)CBO.FillObject(dr, typeof(licthidau));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region binh chọn
        public DataTable getall_binhchon_page(int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[4];
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_binhchon_page]", ref prms, 3, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_binhchon(binhchon vbinhchon, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@mabinhchon", vbinhchon.Mabinhchon);
                i = i + 1;
                prms[i] = new SqlParameter("@noidungbinhluan", vbinhchon.Noidungbinhluan);
                i = i + 1;
                prms[i] = new SqlParameter("@trangthai", vbinhchon.Trangthai);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_binhchon]", ref prms, 4, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public binhchon getby_binhchon(string _mabinhchon, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from binhchon where mabinhchon like  N'" + _mabinhchon + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                binhchon obj = new binhchon();
                obj = (binhchon)CBO.FillObject(dr, typeof(binhchon));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region loại bình chọn chọn
        public DataTable getall_loaibinhchon_page(int _mabinhchon, int _pageIndex, int _pageSize, ref int _rowCount, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                SqlParameter[] prms = new SqlParameter[5];
                prms[i] = new SqlParameter("@mabinhchon", _mabinhchon);
                i = i + 1;
                prms[i] = new SqlParameter("@PageNumber", _pageIndex);
                i = i + 1;
                prms[i] = new SqlParameter("@PageSize", _pageSize);
                i = i + 1;
                prms[i] = new SqlParameter("@outrowcount", SqlDbType.Int, 3);
                prms[i].Direction = ParameterDirection.Output;

                DataTable tbl = SQLExecute.LoadDataFromDBPage("[dbo].[sp_getall_loaibinhchon_page]", ref prms, 4, ref errMsg, ref _rowCount);

                return tbl;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int save_loaibinhchon(loaibinhchon vloaibinhchon, ref string errMsg)
        {
            try
            {
                errMsg = "";
                int i = 0;
                int result = 0;
                SqlParameter[] prms = new SqlParameter[6];
                prms[i] = new SqlParameter("@maloaibinhchon", vloaibinhchon.Maloaibinhchon);
                i = i + 1;
                prms[i] = new SqlParameter("@mabinhchon", vloaibinhchon.Mabinhchon);
                i = i + 1;
                prms[i] = new SqlParameter("@loaibinhchon", vloaibinhchon.Loaibinhchon);
                i = i + 1;
                prms[i] = new SqlParameter("@soluotchon", vloaibinhchon.Soluotchon);
                i = i + 1;
                prms[i] = new SqlParameter("@outreturn", SqlDbType.Int, 1);
                prms[i].Direction = ParameterDirection.Output;

                result = SQLExecute.ExcuteSPOutput("[dbo].[sp_save_loaibinhchon]", ref prms, 5, ref errMsg, "@outreturn");

                return result;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }

        public loaibinhchon getby_loaibinhchon(string _maloaibinhchon, ref string errMsg)
        {
            try
            {
                string sqlstr = "select * from loaibinhchon where maloaibinhchon like  N'" + _maloaibinhchon + "'";
                IDataReader dr = SQLExecute.getIDataReader(sqlstr, ref errMsg);
                loaibinhchon obj = new loaibinhchon();
                obj = (loaibinhchon)CBO.FillObject(dr, typeof(loaibinhchon));
                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}